package com.liming.admin.controller;

import com.liming.aftersales.client.AfterSalesClient;
import com.liming.common.pojo.dto.aftersales.CustomerReviewPageQuery;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.aftersales.CustomerReviewVO;
import com.liming.common.result.LMResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liming
 * @date 2025/3/17
 */
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@Tag(name = "售后评价接口-Web")
@RequestMapping("/admin/after_sales")
public class AfterSalesController {

    private final AfterSalesClient afterSalesClient;

    @Operation(
            summary = "分页 - 客户评论",
            responses = {
                    @ApiResponse(
                            description = "成功",
                            content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = CustomerReviewVO.class))
                    )
            }
    )
    @GetMapping
    public LMResult<PageVO<CustomerReviewVO>> reviewPage(CustomerReviewPageQuery query) {
        return LMResult.success(afterSalesClient.reviewPage(query));
    }

    @Operation(summary = "商家评论")
    @PutMapping("customer_review/{id}")
    public LMResult<Boolean> merchantReview(@PathVariable Long id, @NotBlank(message = "评论内容不能为空") @RequestParam String content) {
        return LMResult.success(afterSalesClient.merchantReview(id, content));
    }

    @Operation(summary = "客户评论删除 - 单个")
    @DeleteMapping("customer_review/{id}")
    public LMResult<Boolean> reviewDelete(@PathVariable Long id) {
        return LMResult.success(afterSalesClient.reviewDelete(id));
    }

    @Operation(summary = "客户评论删除 - 多个")
    @DeleteMapping("customer_review")
    public LMResult<Boolean> reviewDeleteByIds(@RequestBody List<Long> ids) {
        return LMResult.success(afterSalesClient.reviewDelete(ids));
    }
}
